package com.sykj.cloud.system.api.factory;

import com.sykj.cloud.common.core.domain.R;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.system.api.RemoteMemberService;
import com.sykj.cloud.system.api.domain.Member;
import com.sykj.cloud.system.api.model.LoginMember;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 会员服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteMemberFallbackFactory implements FallbackFactory<RemoteMemberService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteMemberFallbackFactory.class);

    @Override
    public RemoteMemberService create(Throwable throwable)
    {
        log.error("会员服务调用失败:{}", throwable.getMessage());
        return new RemoteMemberService()
        {
            @Override
            public R<LoginMember> getMemberInfo(String loginname)
            {
                return R.fail("获取会员失败:" + throwable.getMessage());
            }

            @Override
            public AjaxResult addHttp(Member member) {
                return new AjaxResult(1000,"注册失败");
            }
        };
    }
}
